package com.levis.huolalarobber.utils;

import android.content.Context;

import com.levis.huolalarobber.Constant;

import java.io.File;

/**
 * Created by lwx on 2018/7/30.
 */

public class DeadAppUtil {
    public static boolean appIsDead(Context context) {
        try {
            File deadFileDir = new File(Constant.DEAD_FILE_PATH);
            if (deadFileDir.exists()) {
                File[] files = deadFileDir.listFiles();
                if (files == null || files.length == 0) {
                    return false;
                }
                int ver = 0;
                for (File file : files) {
                    if (file.getName().contains(Constant.DEAD_FILE_NAME)) {
                        String[] name = file.getName().split("_");
                        int curVer = Integer.valueOf(name[name.length - 1]).intValue();
                        if (curVer > ver) ver = curVer;
                    }
                }
                if (ver >= InfoUtil.getVersionCode(context)) {
                    SPutils.put(context, Constant.SP_OPEN, false);
                    return true;
                }
            } else {
                return false;
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return false;
        }
        return false;
    }

}
